using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Security.Cryptography;
using NUnit.Framework;
using System.IO;
using log4net;

namespace dlw.S3Examples
{
    [TestClass, TestFixture]
    public class TestExamples
    {
        private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        // fii foo foo 
        [TestFixtureSetUp]
        public void TestSetup()
        {
            System.Console.WriteLine("Configuring log4net");
            System.IO.FileInfo fi = new System.IO.FileInfo("log4net.config");
            if (!fi.Exists)
            {
                System.Console.WriteLine("file not found");
                return;
            }
            log4net.Config.XmlConfigurator.Configure(fi);
            log.Info("Log4net Configured");
        }
        
        [TestMethod, Test]
        // TestExamples LogTest
        public void LogTest()
        {
            System.Console.WriteLine("123 stesting");
            log.Info("log4net!");
        }
        [TestMethod]
        // TestExamples ListAllMyBuckets
        public void ListAllMyBuckets()
        {
            AWSAuthConnection conn = GetConnection();
            ListAllMyBucketsResponse resp = conn.listAllMyBuckets(null);
            log.Info(resp.ToString());

        }

        // S3Buckets AddBucket dlw.s3.test
        [TestMethod]
        public void AddBucket(string bucketName)
        {
            AWSAuthConnection conn = GetConnection();
            conn.createBucket(bucketName, null, null);
            ListBucketResponse resp = conn.listBucket(bucketName, null, null, 10, null);
            log.Info(resp.ToString());
        }
        // S3Buckets ListBucket dlw.s3.test
        [TestMethod]
        public void ListBucket(string bucketName)
        {
            AWSAuthConnection conn = GetConnection();
            ListBucketResponse resp = conn.listBucket(bucketName, null, null, 10, null);
            log.Info(resp.ToString());
        }

        // S3Buckets PutObject dlw.s3.test  theKey "fooby foo bar"
        [TestMethod]
        public void PutObject(string bucket, string key, string value)
        {
            AWSAuthConnection conn = GetConnection();
            S3Object obj = new S3Object(value, null);
            Response resp = conn.put(bucket, key, obj, null);
            log.Info(resp.ToString());
        }

        // S3Buckets GetObject dlw.s3.test  theKey 
        [TestMethod]
        public void GetObject(string bucket, string key)
        {
            AWSAuthConnection conn = GetConnection();
            GetResponse resp = conn.get(bucket, key, null);
            log.Info(resp.Object.Data);
        }

        private AWSAuthConnection GetConnection()
        {
            AWSAuthConnection conn =
                    new AWSAuthConnection(S3Driver.awsAccessKeyId, S3Driver.awsSecretAccessKey, false, CallingFormat.PATH);
            return conn;
        }

    }
}
